// main.js
import Vue from "vue";
import App from "./App";
import store from "./store/index";
import config from "./config";

Vue.config.productionTip = false;

import "./common/filter"; //注册全局过滤器
//注册全局静态资源地址

// 全局引入 api
import api from "@/common/api";

Vue.prototype.$api = api;

// 全局引入混入mixinjs
import mixin from "@/common/mixin";

Vue.use(mixin);

import uView from "@/components/uview-ui";

Vue.use(uView);

//导入工具包
import utils from "./utils/utils";

// #ifdef H5
import vconsole from "vconsole";
config.isDev && new vconsole();
console.log("当前url--href",window.location.href)
// #endif

uni.$u = Vue.prototype.$u = Vue.prototype.$utils = {
    ...Vue.prototype.$u,
    ...utils,
};

// 跳转目标地址
Vue.prototype.navTo = function (e) {
    if (!e) {
        uni.showToast({
            title: "该功能暂未开放",
            icon: "none",
            duration: 1000,
        });
        return;
    }
    uni.navigateTo({
        url: e,
        fail(err) {
            console.log(err);
        },
    });
};

// 回退
Vue.prototype.backNav = function () {
    const pages = getCurrentPages();
    if (pages.length === 1) {
        uni.redirectTo({url: "/pages/index/index"});
    } else {
        uni.navigateBack({delta: 1});
    }
};

// 封装自定义跳转方法，(h5、小程序通用)
Vue.prototype.reT = Vue.prototype.redirectTo = function (e) {
    if (!e) return;
    uni.redirectTo({url: e});
};

// 封装自定义跳转方法，(h5、小程序通用)
Vue.prototype.reL = Vue.prototype.reLaunchTo = function (e) {
    if (!e) return;
    uni.reLaunch({url: e});
};


import NavBar from "./components/navBar";
Vue.component("NavBar", NavBar);


import TabBar from "./components/tabBar";
Vue.component("TabBar", TabBar);

import NoMore from "./components/noMore"; //空列表组件
Vue.component("NoMore", NoMore);

import coveringLayer from "./components/coveringLayer";
Vue.component("CoveringLayer", coveringLayer);

// import ScTitle from "./components/sc-ui/scTitle";
// Vue.component("scTitle", ScTitle); //自定义标题

import ScButton from "./components/sc-ui/scButton";
Vue.component("ScButton", ScButton); //自定义button

import ScNavBar from "./components/sc-ui/scNavBar";
Vue.component("ScNavBar", ScNavBar); //自定义NavBar

import loadMore from "./components/loadMore.vue"; //加载更多
Vue.component("LoadMore", loadMore);

import scLoading from "./components/sc-ui/scLoading"; //Loading加载中
Vue.component("ScLoading", scLoading);

import scLoadMore from "./components/sc-ui/scLoadMore"; //自定义加载更多和空状态
Vue.component("ScLoadMore", scLoadMore);

import scPopup from "./components/sc-ui/scPopup"; //自定义弹窗
Vue.component("ScPopup", scPopup);

App.mpType = "app";
uni.$app = new Vue({
    store,
    ...App,
}).$mount();
